package com.mcflies.ui.gallery;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.mcflies.ui.R;
import com.mcflies.ui.gallery.ViewGallery.OnTabChangedListener;

public class GalleryMainActivity extends Activity {
	private ViewGallery viewGallery;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery_main);
		viewGallery = (ViewGallery) findViewById(R.id.galleryMain_VG);

		LayoutInflater inflater = LayoutInflater.from(this);
		ListView listView = (ListView) inflater.inflate(R.layout.gallery_tab01,
				null);
		listView.setAdapter(new Tab01Adapter());

		GridView gv = (GridView) inflater.inflate(R.layout.gallery_tab02, null);
		gv.setAdapter(new Tab02Adapter());

		RelativeLayout rl = (RelativeLayout) inflater.inflate(
				R.layout.gallery_tab03, null);

		viewGallery.addItem(rl);
		viewGallery.addItem(gv);
		viewGallery.addItem(listView);
		viewGallery.setOnTabChangedListener(new OnTabChangedListener() {
			@Override
			public void onTabChanged(int tab, View v) {
				Toast.makeText(getBaseContext(), "this is tab " + tab, 0)
						.show();
			}
		});
	}

	class Tab01Adapter extends BaseAdapter {
		@Override
		public int getCount() {
			return 20;
		}

		@Override
		public Object getItem(int position) {
			return 1;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView iv = new ImageView(getBaseContext());
			iv.setImageResource(R.drawable.daily_learning_log);
			return iv;
		}
	}

	class Tab02Adapter extends BaseAdapter {

		@Override
		public int getCount() {
			return 9;
		}

		@Override
		public Object getItem(int position) {
			return 1;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView iv = new ImageView(getBaseContext());
			iv.setImageResource(R.drawable.daily_learning_log);
			iv.setLayoutParams(new GridView.LayoutParams(-2, -2));
			return iv;
		}

	}
}
